package com.ltsznh.android.heartrate;

import android.content.Context;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.SurfaceHolder;
import android.view.SurfaceHolder.Callback;
import android.view.SurfaceView;

/**
 * Created by ltsznh on 14-11-26.
 */
public class RateView extends SurfaceView implements Callback {

    public RateViewThread thread;//线程

    public static Paint clearPaint = new Paint();
    private int height;
    private int width;

    public RateView(Context context, AttributeSet attrs, int dd) {
        super(context, attrs, dd);
        init();
    }

    public RateView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public RateView(Context context) {
        super(context);
        init();
    }

    protected void init() {
        SurfaceHolder surfaceHolder = getHolder();
        surfaceHolder.addCallback(this);

        thread = new RateViewThread(surfaceHolder);
        thread.start();
    }

    @Override
    public void surfaceCreated(SurfaceHolder surfaceHolder) {
        width = getWidth();
        height = getHeight();
        thread.setSize(width, height);
    }

    @Override
    public void surfaceChanged(SurfaceHolder surfaceHolder, int i, int i2, int i3) {
        thread.run();
    }

    @Override
    public void surfaceDestroyed(SurfaceHolder surfaceHolder) {
    }


}
